/*
 * Copyright (C) 2015-2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include <check.h>
#include "PlanetWars2dRT-core/specific/model/universe.h"
#include "PlanetWars2dRT-core/specific/model/planet_default.h"
#include "PlanetWars2dRT-core/specific/model/ship.h"


struct universe_t a_universe;
struct planet_t   a_planet;
struct ship_t     a_ship;

void
tests_setup_init(void)
{
  universe_init_first_time_only(&a_universe);
  a_universe.size.x = 450;
  a_universe.size.y = 450;
  
  planet_set_default(&a_planet);
  a_planet.player_index = 0;
  
  position_2d_uint pos = { 0, 0 };
  a_ship = ship_create_default(&pos, &pos);
}

void
tests_setup_free(void)
{
  universe_destructor(&a_universe);
}


START_TEST(test_add_correct_planet)
{
  a_planet.position.x =  50;
  a_planet.position.y =  50;
  ck_assert(universe_add_planet_unsafe(&a_universe, &a_planet));
  ck_assert(universe_get_nb_planets(&a_universe) == 1);
}
END_TEST

START_TEST(test_add_correct_planets)
{ 
  a_planet.position.x =  50;
  a_planet.position.y =  50;
  ck_assert(universe_add_planet_unsafe(&a_universe, &a_planet));
  ck_assert(universe_get_nb_planets(&a_universe) == 1);
  
  a_planet.position.x = 150;
  a_planet.position.y = 150;
  ck_assert(universe_add_planet_unsafe(&a_universe, &a_planet));
  ck_assert(universe_get_nb_planets(&a_universe) == 2);
  
  a_planet.position.x = 300;
  a_planet.position.y = 300;
  ck_assert(universe_add_planet_unsafe(&a_universe, &a_planet));
  ck_assert(universe_get_nb_planets(&a_universe) == 3);
  
  a_planet.position.x = 100;
  a_planet.position.y = 300;
  ck_assert(universe_add_planet_unsafe(&a_universe, &a_planet));
  ck_assert(universe_get_nb_planets(&a_universe) == 4);
}
END_TEST

START_TEST(test_add_incorrect_planet)
{
  ck_assert(universe_get_nb_planets(NULL) == 0);
  ck_assert(!universe_add_planet(NULL,        NULL));
  ck_assert(universe_get_nb_planets(NULL) == 0);
  ck_assert(!universe_add_planet(&a_universe, NULL));
  ck_assert(universe_get_nb_planets(NULL) == 0);
  ck_assert(!universe_add_planet(NULL,        &a_planet));
  ck_assert(universe_get_nb_planets(NULL) == 0);
  
  ck_assert(universe_get_nb_planets(&a_universe) == 0);
  a_planet.position.x = 800;
  a_planet.position.y = 800;
  ck_assert(!universe_add_planet_unsafe(&a_universe, &a_planet));
  ck_assert(universe_get_nb_planets(&a_universe) == 0);
}
END_TEST

START_TEST(test_remove_planets)
{
  ck_assert(universe_get_nb_planets(NULL) == 0);
  universe_remove_planets(NULL);
  ck_assert(universe_get_nb_planets(NULL) == 0);
  
  ck_assert(universe_get_nb_planets(&a_universe) == 0);
  universe_remove_planets(&a_universe);
  ck_assert(universe_get_nb_planets(&a_universe) == 0);
  universe_remove_planets(&a_universe);
  ck_assert(universe_get_nb_planets(&a_universe) == 0);
  
  ck_assert(universe_add_planet_unsafe(&a_universe, &a_planet));
  ck_assert(universe_get_nb_planets(&a_universe) == 1);
  universe_remove_planets(&a_universe);
  ck_assert(universe_get_nb_planets(&a_universe) == 0);
  universe_remove_planets(&a_universe);
  ck_assert(universe_get_nb_planets(&a_universe) == 0);
  
  ck_assert(universe_add_planet_unsafe(&a_universe, &a_planet));
  ck_assert(!universe_add_planet_unsafe(&a_universe, &a_planet));
  ck_assert(universe_get_nb_planets(&a_universe) == 1);
  universe_remove_planets(&a_universe);
  ck_assert(universe_get_nb_planets(&a_universe) == 0);
  universe_remove_planets(&a_universe);
  ck_assert(universe_get_nb_planets(&a_universe) == 0);
}
END_TEST


START_TEST(test_add_correct_ship)
{
  ck_assert(universe_get_nb_ships(&a_universe) ==  0);
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) ==  1);
  ck_assert(ship_equals_except_observers(universe_get_ship_no_check(&a_universe, 0),
					 &a_ship));
  
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) ==  2);
  ck_assert(ship_equals_except_observers(universe_get_ship_no_check(&a_universe, 1),
					 &a_ship));
  
  a_ship.size.x = 1;
  a_ship.size.y = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) ==  3);
  
  a_ship.size.x = 2;
  a_ship.size.y = 2;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) ==  4);
  
  ship_set_top_left_position_current_x(&a_ship, 0);
  ship_set_top_left_position_to_go_x  (&a_ship, 0);
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) ==  5);
  
  ship_set_top_left_position_current_x(&a_ship, 0);
  ship_set_top_left_position_to_go_x  (&a_ship, 1);
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) ==  6);
  
  ship_set_top_left_position_current_x(&a_ship, 0);
  ship_set_top_left_position_to_go_x  (&a_ship, 5);
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) ==  7);
  
  ship_set_top_left_position_current_y(&a_ship, 0);
  ship_set_top_left_position_to_go_y  (&a_ship, 0);
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) ==  8);
  
  ship_set_top_left_position_current_y(&a_ship, 0);
  ship_set_top_left_position_to_go_y  (&a_ship, 1);
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) ==  9);
  
  ship_set_top_left_position_current_y(&a_ship, 0);
  ship_set_top_left_position_to_go_y  (&a_ship, 5);
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 10);
  
  ship_set_top_left_position_current_x(&a_ship, 0);
  ship_set_top_left_position_to_go_x  (&a_ship, 5);
  ship_set_top_left_position_current_y(&a_ship, 0);
  ship_set_top_left_position_to_go_y  (&a_ship, 5);
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 11);
  
  ship_set_top_left_position_current_x(&a_ship, 5);
  ship_set_top_left_position_to_go_x  (&a_ship, 0);
  ship_set_top_left_position_current_y(&a_ship, 5);
  ship_set_top_left_position_to_go_y  (&a_ship, 0);
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 12);
}
END_TEST

START_TEST(test_add_incorrect_ship)
{
  ck_assert(universe_get_nb_ships(NULL) == 0);
  ck_assert(!universe_add_ship(NULL,        NULL));
  ck_assert(universe_get_nb_ships(NULL) == 0);
  ck_assert(!universe_add_ship(&a_universe, NULL));
  ck_assert(universe_get_nb_ships(NULL) == 0);
  ck_assert(!universe_add_ship(NULL,        &a_ship));
  ck_assert(universe_get_nb_ships(NULL) == 0);
  
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  ship_set_top_left_position_current_x(&a_ship, a_universe.size.x + 1);
  ship_set_top_left_position_current_y(&a_ship, a_universe.size.y / 2);
  ck_assert(!universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  ship_set_top_left_position_current_x(&a_ship, a_universe.size.x / 2);
  ship_set_top_left_position_current_y(&a_ship, a_universe.size.y + 1);
  ck_assert(!universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  ship_set_top_left_position_current_x(&a_ship, a_universe.size.x / 2);
  ship_set_top_left_position_current_y(&a_ship, a_universe.size.y / 2);
  
  a_ship.size.x = 1;
  a_ship.size.y = a_universe.size.y + 1;
  ck_assert(!universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  a_ship.size.x = a_universe.size.x + 1;
  a_ship.size.y = 1;
  ck_assert(!universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  a_ship.size.x = a_universe.size.x + 1;
  a_ship.size.y = a_universe.size.y + 1;
  ck_assert(!universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
}
END_TEST

START_TEST(test_remove_ships)
{
  ck_assert(universe_get_nb_ships(NULL) == 0);
  universe_remove_ships(NULL);
  ck_assert(universe_get_nb_ships(NULL) == 0);
  
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 3);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 2;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 3);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 3);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 3);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 200;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 3);
  universe_remove_ships(&a_universe);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
}
END_TEST

START_TEST(test_remove_destroyed_ships)
{
  ck_assert(universe_get_nb_ships(NULL) == 0);
  ck_assert(universe_remove_destroyed_ships(NULL) == 0);
  ck_assert(universe_get_nb_ships(NULL) == 0);
  
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  ship_destroy(universe_get_ship_no_check(&a_universe, 0));
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 1);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  universe_remove_ships(&a_universe);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  ship_destroy(universe_get_ship_no_check(&a_universe, 0));
  ship_destroy(universe_get_ship_no_check(&a_universe, 1));
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 2);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 0);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ship_destroy(universe_get_ship_no_check(&a_universe, 1));
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 1);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  ck_assert(universe_get_ship_no_check(&a_universe, 0)->player_index == 0);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  universe_remove_ships(&a_universe);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ship_destroy(universe_get_ship_no_check(&a_universe, 0));
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 1);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  ck_assert(universe_get_ship_no_check(&a_universe, 0)->player_index == 1);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  universe_remove_ships(&a_universe);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 2;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ship_destroy(universe_get_ship_no_check(&a_universe, 0));
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 1);
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  ck_assert(universe_get_ship_no_check(&a_universe, 0)->player_index != 0);
  ck_assert(universe_get_ship_no_check(&a_universe, 0)->player_index != 0);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  universe_remove_ships(&a_universe);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 2;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ship_destroy(universe_get_ship_no_check(&a_universe, 1));
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 1);
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  ck_assert(universe_get_ship_no_check(&a_universe, 0)->player_index != 1);
  ck_assert(universe_get_ship_no_check(&a_universe, 1)->player_index != 1);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  universe_remove_ships(&a_universe);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 2;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ship_destroy(universe_get_ship_no_check(&a_universe, 2));
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 1);
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  ck_assert(universe_get_ship_no_check(&a_universe, 0)->player_index != 2);
  ck_assert(universe_get_ship_no_check(&a_universe, 1)->player_index != 2);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 2);
  universe_remove_ships(&a_universe);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 2;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ship_destroy(universe_get_ship_no_check(&a_universe, 0));
  ship_destroy(universe_get_ship_no_check(&a_universe, 1));
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 2);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  ck_assert(universe_get_ship_no_check(&a_universe, 0)->player_index == 2);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  universe_remove_ships(&a_universe);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 2;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ship_destroy(universe_get_ship_no_check(&a_universe, 1));
  ship_destroy(universe_get_ship_no_check(&a_universe, 2));
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 2);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  ck_assert(universe_get_ship_no_check(&a_universe, 0)->player_index == 0);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  universe_remove_ships(&a_universe);
  
  a_ship.player_index = 0;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 1;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  a_ship.player_index = 2;
  ck_assert(universe_add_ship_unsafe(&a_universe, &a_ship));
  ship_destroy(universe_get_ship_no_check(&a_universe, 0));
  ship_destroy(universe_get_ship_no_check(&a_universe, 2));
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 2);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  ck_assert(universe_get_ship_no_check(&a_universe, 0)->player_index == 1);
  ck_assert(universe_remove_destroyed_ships(&a_universe) == 0);
  ck_assert(universe_get_nb_ships(&a_universe) == 1);
  universe_remove_ships(&a_universe);
}
END_TEST


Suite*
universe_suite(void)
{
  Suite* s = suite_create("Universe");
  
  TCase* tc_add_planets = tcase_create("Add planets");
  tcase_add_checked_fixture(tc_add_planets,
			    tests_setup_init, tests_setup_free);
  tcase_add_test(tc_add_planets, test_add_correct_planet);
  tcase_add_test(tc_add_planets, test_add_correct_planets);
  tcase_add_test(tc_add_planets, test_add_incorrect_planet);
  suite_add_tcase(s, tc_add_planets);
  
  TCase* tc_rm_planets = tcase_create("Remove planets");
  tcase_add_checked_fixture(tc_rm_planets,
			    tests_setup_init, tests_setup_free);
  tcase_add_test(tc_rm_planets, test_remove_planets);
  suite_add_tcase(s, tc_rm_planets);
  
  TCase* tc_add_ships = tcase_create("Add ships");
  tcase_add_checked_fixture(tc_add_ships,
			    tests_setup_init, tests_setup_free);
  tcase_add_test(tc_add_ships, test_add_correct_ship);
  tcase_add_test(tc_add_ships, test_add_incorrect_ship);
  suite_add_tcase(s, tc_add_ships);
  
  TCase* tc_rm_ships = tcase_create("Remove ships");
  tcase_add_checked_fixture(tc_rm_ships,
			    tests_setup_init, tests_setup_free);
  tcase_add_test(tc_rm_ships, test_remove_ships);
  tcase_add_test(tc_rm_ships, test_remove_destroyed_ships);
  suite_add_tcase(s, tc_rm_ships);
  
  return s;
}

int
main(void)
{
  size_t number_failed;
  Suite* s;
  SRunner* sr;

  s = universe_suite();
  sr = srunner_create(s);
  
  srunner_run_all(sr, CK_NORMAL);
  number_failed = srunner_ntests_failed(sr);
  srunner_free(sr);
  
  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
